/*******************************************************************************
File: 0_organize
Project: CPKIN 
Purpose: This .do file separates the Endline dataset by respondent: splitting CPFP data from other data
Author: Akshay Dixit
Date Created: Jan 23, 2019
Data last modified: June 26, 2020
********************************************************************************/

clear all
set more off

***THIS IS THE INPUT THAT MUST BE CHANGED SPECIFIC TO THE USER***
*gl identity ""
*gl user "" 
	   
********************************************************************************

***Creating Global File Paths***'
gl data "$user/data"
gl dof "$user/do files"
gl analysis "$user/analysis"

********************************************************************************

u "$data/endline_master.dta", clear

tab type_survey						//753 adult, 699 child, 124 chief, 122 FPs
codebook village_id1				//From 126 villages
codebook chiefdom					//12 chiefdoms
bysort type_survey: tab treatment	//All samples roughly balanced, except FPs: 65 treatment (53%), 57 control (47%)

preserve
	contract village_id1 treatment
	tab treatment					//64 treatment villages, 62 control villages
restore

g adult_survey = (type_survey == "Adult")
g child_survey = (type_survey == "child")
g chief_survey = (type_survey == "chief")
g fp_survey = (type_survey == "fp")

bysort village_id1: egen adult_count = total(adult_survey)
bysort village_id1: egen child_count = total(child_survey)
bysort village_id1: egen chief_count = total(chief_survey)
bysort village_id1: egen fp_count = total(fp_survey)

				
tab focal_status		
tab treatment if focal_status == 3	
tab village_id1 if focal_status == 3 
tab village_id1 if fp_count > 1 & focal_status == 3
foreach i in 105 149 151 231 233 {
	tab focal_status if village_id1 == `i' 
}

	/*	5 volunteer workers said they were no longer active at the endline.
		Village IDs: 105, 149, 151, 231, 233.
		In all these villages, the active workers were also surveyed.
	*/	
	
********************************************************************************

***Separating the volunteer worker dataset from the others***


preserve
	keep if type_survey == "fp"
	save "$data/endline_fp_data.dta", replace
restore

drop if type_survey == "fp"
save "$data/endline_adult_chief_child_data.dta", replace

********************************************************************************

clear






